package controleponto.db.dao;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

public abstract class EntityDAO {
	
	private static EntityManager em;
	
	public EntityManager getEntityManager() {
		return em = Persistence.createEntityManagerFactory("ControlePontoJPA").createEntityManager();
	}
	
	public void AdicionaDAO(Object item) {
		em.getTransaction().begin();
		em.persist(item);
		em.getTransaction().commit();
	}
	
	public void AtuallizaDAO(Object item) {
		em.getTransaction().begin();
		em.merge(item);
		em.getTransaction().commit();
	}
	
	public void RemoveDAO(Object item) {
		Object entity = em.find(item.getClass(), item);
		
		em.getTransaction().begin();
		em.remove(entity);
		em.getTransaction().commit();
	}

}
